﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MadiFracas
{
	/// <summary>
	/// Lógica de interacción para MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{

		CountryManager cman;

		public MainWindow()
		{
			InitializeComponent();
		}

		private void menuItemSalir_Click(object sender, RoutedEventArgs e)
		{
			this.Close();
		}

		private void botonGenerar_Click(object sender, RoutedEventArgs e)
		{
			int ancho = Convert.ToInt32(sliderAncho.Value);
			int alto = Convert.ToInt32(sliderAlto.Value);

			cman = new CountryManager(alto, ancho);
			texto.Text = cman.ToString();

			canvas.Children.Clear();
			labelInfo.Content = cman.Countries.Count.ToString() + " paises!";
			linea();
		}

		private void linea()
		{
			int SCALE = 50;
			int STARTX = 50;
			int STARTY = 50;

			PathFigure pf = new PathFigure();
			pf.StartPoint = new Point(STARTX, STARTY);

			PathSegmentCollection segments = new PathSegmentCollection();

			//int pais = cman.Countries.First();
			int pais = 0;
			List<Point> puntos = Util.obtenerPuntosPais(cman, pais);

			Point p;
			for (int i = 0; i < puntos.Count; i++)
			//foreach (Point p in puntos)
			{
				p = new Point(puntos.ElementAt(i).X, puntos.ElementAt(i).Y);
				LineSegment ls = new LineSegment();
				p.X = p.X * SCALE;
				p.Y = p.Y * SCALE;
				ls.Point = p;
				segments.Add(ls);
			}

			//for (int i = 0; i < cman.Size.X; i++)
			//{
			//    for (int j = 0; j < cman.Size.Y; j++)
			//    {
			//        LineSegment ls = new LineSegment();
			//        ls.Point = new Point(STARTX + (i * SCALE), STARTY + (j * SCALE));
			//        segments.Add(ls);
			//    }
			//}

			pf.Segments = segments;

			PathFigureCollection pfc = new PathFigureCollection();
			pfc.Add(pf);

			PathGeometry pg = new PathGeometry();
			pg.Figures = pfc;

			Path path = new Path();
			path.Stroke = Brushes.Black;
			path.StrokeThickness = 1;
			path.Data = pg;

			canvas.Children.Add(path);
		}

		private void sliderAlto_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
		{
			labelAlto.Content = e.NewValue.ToString();
		}

		private void sliderAncho_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
		{
			labelAncho.Content = e.NewValue.ToString();
		}


	}
}
